import {
  getUserPassRate,
  updatePassRateConf,
  getPassRateConf,
} from '../../services/channel/api';


export default {
  namespace: 'riskDetection',

  state: {

    loading: true,

    getUserPassRateData: [],

    getPassRateConfData: {},

  },

  effects: {

    *fetchGetUserPassRate({payload,callback}, { call, put }) {
      const response = yield call(getUserPassRate, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: { getUserPassRateData: response.data },
        });
      }
      if (callback && response) callback(response);
    },

    *fetchGetPassRateConf({payload,callback}, { call, put }) {
      const response = yield call(getPassRateConf, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: { getPassRateConfData: response.data },
        });
      }
      if (callback && response) callback(response);
    },

    *fetchUpdatePassRateConf({payload,callback}, { call, put }) {
      const response = yield call(updatePassRateConf, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: { updatePassRateConfData: response.data },
        });
      }
      if (callback && response) callback(response);
    },
    
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },

};
